home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / FredFish PD 318.adf / WaveMaker / wavemaker.c < prev    next >
C/C++ Source or Header  |  1990-02-14  |  75KB  |  2,157 lines

  1. /**********************************************************************/
  2. /*                                                                    */
  3. /*  WaveMaker - a program to allow a user to construct waveforms      */
  4. /*              by superposition of harmonic sine waves.              */
  5. /*                                                                    */
  6. /*                                                                    */
  7. /*  This program is intended for beginning physics students to help   */
  8. /*  them get a better intuitive feel for constructing a complex wave  */
  9. /*  form from a sum of harmonics.  Musicians may also find it         */
  10. /*  useful.                                                           */
  11. /*                                                                    */
  12. /*  For program operation see WaveMaker.doc.                          */
  13. /*                                                                    */
  14. /*  This program was written in Lattice C, version 5.04.02.  It is    */
  15. /*  compiled with the command:  lc -O -j30.                           */
  16. /*                                                                    */
  17. /*  It is linked with the following "with" file:                      */
  18. /*        from lib:c.o                                                */
  19. /*        wavemaker.o                                                 */
  20. /*        lib lib:lcm.lib lib:lc.lib lib:amiga.lib                    */
  21. /*        SMALLCODE                                                   */
  22. /*        SMALLDATA                                                   */
  23. /*                                                                    */
  24. /*  WaveMaker is freely distributable as long as it is not sold for   */
  25. /*  profit.  It is permitted (encouraged) to include it on software   */
  26. /*  collections sold for a nominal sum, such as club disks and        */
  27. /*  Fish disks.  Copyright is retained by the author.                 */
  28. /*                                                                    */
  29. /*  Thanks are due to those people who posted example programs in     */
  30. /*  the BIX listings area.  One good example is worth several chapters*/
  31. /*  of explanation.  Of particular use were gad.c and menu.c. both by */
  32. /*  John Draper, and scales.c by Steven A. Bennett.                   */
  33. /*                                                                    */
  34. /*  Comments, bugs, complaints, and praise may be sent to me at       */
  35. /*                  Thomas Meyer                                      */
  36. /*                  12 Physics, Iowa State University                 */
  37. /*                  Ames, IA 50010                                    */
  38. /*                  BIX: TMEYER,  BITNET:MEYER@ALISUVAX               */
  39. /*                                                                    */
  40. /**********************************************************************/
  41. /*                                                                    */
  42. /* Update history:                                                    */
  43. /*    1/24/90    Version 1.1                                          */
  44. /*                 Easy game added                                    */
  45. /*                 Fixed crashes from rawkey>64                       */
  46. /*                 Closed down in correct order                       */
  47. /*                 Game doesn't interfere with amps[]                 */
  48. /*                 Random seed from timer                             */
  49. /*    1/21/90    Version 1.0 released on AAAUG club disk              */
  50. /**********************************************************************/
  51.  
  52. #include <math.h>
  53. #include <stdio.h>
  54. #include <exec/types.h>
  55. #include <exec/nodes.h>
  56. #include <exec/lists.h>
  57. #include <exec/ports.h>
  58. #include <exec/devices.h>
  59. #include <exec/memory.h>
  60. #include <hardware/custom.h>
  61. #include <hardware/dmabits.h>
  62. #include <libraries/dos.h>
  63. #include <devices/audio.h>
  64. #include <devices/inputevent.h>
  65. #include <intuition/intuition.h>
  66. #include <graphics/gfxbase.h>
  67. #include <graphics/gfx.h>
  68. #include <graphics/clip.h>
  69. #include <graphics/view.h>
  70. #include <graphics/rastport.h>
  71. #include <graphics/layers.h>
  72.  
  73. extern struct MsgPort *CreatePort();
  74. extern VOID ModifyProp();
  75. extern VOID PrintIText();
  76.  
  77. struct IntuitionBase *IntuitionBase;
  78. struct GfxBase *GfxBase;
  79. struct Window *Window;
  80. struct Screen *Screen;
  81. struct ViewPort *ViewPort;
  82. struct RastPort *rport;
  83. struct IntuiMessage *mesg;
  84. struct IOAudio *ioa,*audio,*finish,*audchan[4];
  85.  
  86. /****************************************/
  87. /*  Build the Intuition Gadgets         */
  88. /****************************************/
  89.  
  90. /*      Define Logicals for GadgetIDs   */
  91.  
  92. #define HARMON0 0
  93. #define HARMON1 1
  94. #define HARMON2 2
  95. #define HARMON3 3
  96. #define HARMON4 4
  97. #define HARMON5 5
  98. #define HARMON6 6
  99. #define HARMON7 7
  100. #define INTEG   0
  101. #define UPARROW 8
  102. #define DNARROW 16
  103. #define PROPOR  24
  104. #define PLUSMINUS 32
  105. #define YES     1
  106. #define NO      0
  107. #define NBR_IOA_STRUCTS 6
  108.  
  109. /* define logicals for ErrExit */
  110.  
  111. #define SUCCESS         0
  112. #define INTUITION_FAIL  1
  113. #define GRAPHICS_FAIL   2
  114. #define PORTPN_FAIL     3
  115. #define PORTP0_FAIL     4
  116. #define AUDIOALLOC_FAIL 5
  117. #define AUDIO_FAIL      6
  118. #define USERSOUND_FAIL  7
  119. #define REFSOUND_FAIL   8
  120. #define SCREEN_FAIL     9
  121. #define WINDOW_FAIL    10
  122.  
  123. /*  Miscellaneous logicals */
  124.  
  125. #define INTUITION_REV 0
  126. #define GRAPHICS_REV 0
  127.  
  128. #define TWOPI 6.283185
  129.  
  130. /*************************************/
  131. /*  Global variables and structures  */
  132. /*************************************/
  133.  
  134. SHORT sinewave[8][513];
  135. LONG amps[8],refamps[8];
  136. LONG maxuser=1,maxref=1;
  137. LONG maxamp=16066;
  138. BYTE waveform[514],refform[514];
  139. BYTE *usersound,*refsound;
  140. BYTE sunit=0x0F;
  141. SHORT audiochan[128] ={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  142.                    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  143.                    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  144.                    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  145.                    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  146.                    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  147.                    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  148.                    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
  149. SHORT waiting[5]={NO, NO, NO, NO, NO};
  150. SHORT gameon=NO;
  151. VOID ErrExit();
  152.  
  153. /*  Structures for drawing waveforms    */
  154.  
  155. USHORT userwave[513][2],refwave[513][2];
  156.  
  157. struct Border UWave_brd1 =
  158. {
  159.     64,13,                        /* LeftEdge, TopEdge              */
  160.     4,0,JAM1,                     /* FrontPen, BackPen, DrawMode    */
  161.     127,(APTR)&userwave[0][0],    /* Count, *XY                     */
  162.     NULL                          /* *NextBorder                    */
  163. };
  164. struct Border UWave_brd2 =
  165. {
  166.     64,13,                        /* LeftEdge, TopEdge              */
  167.     4,0,JAM1,                     /* FrontPen, BackPen, DrawMode    */
  168.     127,(APTR)&userwave[126][0],  /* Count, *XY                     */
  169.     (APTR)&UWave_brd1             /* *NextBorder                    */
  170. };
  171. struct Border UWave_brd3 =
  172. {
  173.     64,13,                        /* LeftEdge, TopEdge              */
  174.     4,0,JAM1,                     /* FrontPen, BackPen, DrawMode    */
  175.     127,(APTR)&userwave[252][0],  /* Count, *XY                     */
  176.     (APTR)&UWave_brd2             /* *NextBorder                    */
  177. };
  178. struct Border UWave_brd4 =
  179.     64,13,                        /* LeftEdge, TopEdge              */
  180.     4,0,JAM1,                     /* FrontPen, BackPen, DrawMode    */
  181.     127,(APTR)&userwave[378][0],  /* Count, *XY                     */
  182.     (APTR)&UWave_brd3             /* *NextBorder                    */
  183. };
  184. struct Border UWave_brd5 =
  185. {
  186.     64,13,                        /* LeftEdge, TopEdge              */
  187.     4,0,JAM1,                     /* FrontPen, BackPen, DrawMode    */
  188.     9,(APTR)&userwave[504][0],    /* Count, *XY                     */
  189.     (APTR)&UWave_brd4             /* *NextBorder                    */
  190. };
  191. struct Border RWave_brd1 =
  192. {
  193.     64,13,                        /* LeftEdge, TopEdge              */
  194.     6,0,JAM1,                     /* FrontPen, BackPen, DrawMode    */
  195.     127,(APTR)&refwave[0][0],     /* Count, *XY                     */
  196.     NULL                          /* *NextBorder                    */
  197. };
  198. struct Border RWave_brd2 =
  199. {
  200.     64,13,                        /* LeftEdge, TopEdge              */
  201.     6,0,JAM1,                     /* FrontPen, BackPen, DrawMode    */
  202.     127,(APTR)&refwave[126][0],   /* Count, *XY                     */
  203.     (APTR)&RWave_brd1             /* *NextBorder                    */
  204. };
  205. struct Border RWave_brd3 =
  206. {
  207.     64,13,                        /* LeftEdge, TopEdge              */
  208.     6,0,JAM1,                     /* FrontPen, BackPen, DrawMode    */
  209.     127,(APTR)&refwave[252][0],   /* Count, *XY                     */
  210.     (APTR)&RWave_brd2             /* *NextBorder                    */
  211. };
  212. struct Border RWave_brd4 =
  213.     64,13,                        /* LeftEdge, TopEdge              */
  214.     6,0,JAM1,                     /* FrontPen, BackPen, DrawMode    */
  215.     127,(APTR)&refwave[378][0],   /* Count, *XY                     */
  216.     (APTR)&RWave_brd3             /* *NextBorder                    */
  217. };
  218. struct Border RWave_brd5 =
  219. {
  220.     64,13,                        /* LeftEdge, TopEdge              */
  221.     6,0,JAM1,                     /* FrontPen, BackPen, DrawMode    */
  222.     9,(APTR)&refwave[504][0],     /* Count, *XY                     */
  223.     (APTR)&RWave_brd4             /* *NextBorder                    */
  224. };
  225.  
  226. /*      Declare the character buffer for IntuitText structures 
  227.         (to be filled later).                                         */
  228.     
  229. char textbuf[6]="    0";
  230.  
  231. struct IntuiText textamp =
  232. {
  233.     1,0,JAM2,           /* FrontPen, BackPen, DrawMode            */
  234.     0,0,                /* LeftEdge, TopEdge (use offsets to set) */
  235.     NULL,               /* *ITextFont   (use default)             */
  236.     (APTR)&textbuf,     /* *IText (fill later)                    */
  237.     NULL                /* *NextText                              */
  238. };
  239.  
  240. /*   Border structures for the amplitude display box                  */
  241.  
  242. USHORT BoxPairsb[9][2]=
  243. {
  244.     2,11, 53,11, 53,2, 54,2, 54,11,
  245.     55,11, 55,2, 56,2, 56,11       /* Brown shadow around int */
  246. };
  247.  
  248. struct Border brdi1b =
  249. {
  250.     -2,-2,2,0,          /* LeftEdge, TopEdge, FrontPen, BackPen   */
  251.     JAM1, 9,            /* DrawMode, Count                        */
  252.     (APTR)&BoxPairsb,   /* *XY                                    */
  253.     NULL                /* *NextBorder                            */
  254. };
  255.  
  256. USHORT BoxPairs[5][2]=
  257. {
  258.     0, 0,  52,0,  52,10,   0,10,  0,0  /* Coords of box  */
  259. };
  260.  
  261. struct Border brdi1 =
  262. {
  263.     -2,-2,1,0,          /* LeftEdge, TopEdge, FrontPen, BackPen   */
  264.     JAM1, 5,            /* DrawMode, Count                        */
  265.     (APTR)&BoxPairs,    /* *XY                                    */
  266.     &brdi1b             /* *NextBorder                            */
  267. };
  268.  
  269. /*************************************/
  270. /*     First amplitude gadgets       */
  271. /*************************************/
  272.  
  273. /*  Proportional gadget  */
  274.  
  275. struct PropInfo prop_info1 =
  276. {
  277.     AUTOKNOB|FREEVERT,  /* Flags                                  */
  278.     0xFFFF,0xFFFF,      /* HorizPot, VertPot                      */
  279.     0x0800,0x0800,      /* HorizBody, VertBody                    */
  280.     16,64,              /* CWidth,CHeight                         */
  281.     0x0800,0x0800,      /* HPotRes, VPotRes                       */
  282.     0,0                 /* LeftBorder, TopBorder                  */
  283. };
  284.  
  285. struct IntuiText protext1 =
  286. {
  287.     5, 2, JAM2,         /* FrontPen, BackPen, DrawMode            */
  288.     -20, 3,             /* LeftEdge, TopEdge                      */
  289.     NULL,"1:",          /* *ITextFont, *Itext                     */
  290.     NULL                /* *NextText                              */
  291. };
  292.  
  293. struct Image empty1,empty2,empty3,empty4,empty5,empty6,empty7,empty8;
  294.  
  295. struct Gadget propor1 =
  296. {
  297.     NULL,65,113,               /* *NextGadget, LeftEdge, TopEdge     */
  298.     14,69,GADGHCOMP|AUTOKNOB,  /* Width, Height, Flags               */
  299.     RELVERIFY|GADGIMMEDIATE,   /* Activation                         */
  300.     PROPGADGET,(APTR)&empty1,  /* GadgetType, GadgetRender           */
  301.     NULL,                      /* SelectRender                       */
  302.     (APTR)&protext1,0,         /* *GadgetText, MutualExclude         */
  303.     (APTR)&prop_info1,         /* SpecialInfo                        */
  304.     HARMON0|PROPOR,            /* GadgetID                           */
  305.     NULL                       /* UserData                           */
  306. };
  307.  
  308. /*   Up arrow gadget     */
  309.  
  310. USHORT updn_shadata[] = {2,7, 17,7, 17,1, 18,1, 18,7, 19,7, 19,1};
  311. struct Border updn_shadow =
  312. {
  313.     -2,-1,2,0,              /* LeftEdge, TopEdge, FrontPen, BackPen */
  314.     JAM1,7,                 /* DrawMode, Count                      */
  315.     (APTR)&updn_shadata,    /* *XY                                  */
  316.     NULL                    /* *NextBorder                          */
  317. };
  318.  
  319. USHORT updn_data[] = {0,0, 0,6, 16,6, 16,0, 0,0};
  320. struct Border updn_border =
  321. {
  322.     -2,-1,1,0,              /* LeftEdge, TopEdge, FrontPen, BackPen */
  323.     JAM1,5,                 /* DrawMode, Count                      */
  324.     (APTR)&updn_data,       /* *XY                                  */
  325.     &updn_shadow            /* *NextBorder                          */
  326. };
  327.  
  328. USHORT uparr_data[] = {8,2, 3,4, 13,4, 8,2};
  329. struct Border up_arr =
  330. {
  331.     -2,-1,1,0,              /* LeftEdge, TopEdge, FrontPen, BackPen */
  332.     JAM1,4,                 /* DrawMode, Count                      */
  333.     (APTR)&uparr_data,      /* *XY                                  */
  334.     &updn_border            /* *NextBorder                          */
  335. };
  336.  
  337. struct Gadget up1 =
  338. {
  339.     &propor1,44,143,           /* *NextGadget, LeftEdge, TopEdge     */
  340.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  341.     GADGIMMEDIATE,             /* Activation                         */
  342.     BOOLGADGET,(APTR)&up_arr, /* GadgetType, GadgetRender           */
  343.     NULL,                      /* SelectRender                       */
  344.     NULL,0,                    /* *GadgetText, MutualExclude         */
  345.     NULL,                      /* SpecialInfo                        */
  346.     HARMON0|UPARROW,           /* GadgetID                           */
  347.     NULL                       /* UserData                           */
  348. };
  349.  
  350. /*   down arrow gadget  */
  351.  
  352. USHORT dnarr_data[] = {3,2, 13,2, 8,4, 3,2};
  353. struct Border dn_arr =
  354. {
  355.     -2,-1,1,0,              /* LeftEdge, TopEdge, FrontPen, BackPen */
  356.     JAM1,4,                 /* DrawMode, Count                      */
  357.     (APTR)&dnarr_data,      /* *XY                                  */
  358.     &updn_border            /* *NextBorder                          */
  359. };
  360.  
  361. struct Gadget dn1 =
  362. {
  363.     &up1,44,152,               /* *NextGadget, LeftEdge, TopEdge     */
  364.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  365.     GADGIMMEDIATE,             /* Activation                         */
  366.     BOOLGADGET,(APTR)&dn_arr,  /* GadgetType, GadgetRender           */
  367.     NULL,                      /* SelectRender                       */
  368.     NULL,0,                    /* *GadgetText, MutualExclude         */
  369.     NULL,                      /* SpecialInfo                        */
  370.     HARMON0|DNARROW,           /* GadgetID                           */
  371.     NULL                       /* UserData                           */
  372. };
  373.  
  374. /*  Change sign gadget  */
  375.  
  376.                 /* tie shadow for proportional gadget here since
  377.         I can't get border structures working for prop gadgets */
  378. USHORT pshad_data[] = {24,17, 38,17, 38,-51, 39,-51, 39,17, 40,17, 40,-51};
  379.  
  380. struct Border propshad =
  381. {
  382.     -2,-2,2,0,          /* LeftEdge, TopEdge, FrontPen, BackPen   */
  383.     JAM1, 7,            /* DrawMode, Count                        */
  384.     (APTR)&pshad_data,  /* *XY                                    */
  385.     NULL                /* *NextBorder                            */
  386. };
  387.  
  388. USHORT plus1[] = {5,3, 9,3};
  389. USHORT plus2[] = {7,2, 7,4};
  390. USHORT minus[] = {5,6, 9,6};
  391. USHORT plmi_data[] = {0,0, 0,8, 15,8, 15,0, 0,0};
  392. USHORT plmi_datas[]= {2,9, 16,9, 16,1, 17,1, 17,9, 18,9, 18,1};
  393.  
  394. struct Border plmi1 =
  395. {
  396.     -2,-1,1,0,            /* LeftEdge, TopEdge, Frontpen, BackPen */
  397.     JAM1,2,               /* DrawMode, Count                      */
  398.     (APTR)&plus1,         /* *XY                                  */
  399.     &propshad             /* *NextBorder                     */
  400. };
  401.  
  402. struct Border plmi2 =
  403. {
  404.     -2,-1,1,0,              /* LeftEdge, TopEdge, Frontpen, BackPen */
  405.     JAM1,2,                 /* DrawMode, Count                      */
  406.     (APTR)&plus2,&plmi1     /* *XY, *NextBorder                     */
  407. };
  408.  
  409. struct Border plmi3 =
  410. {
  411.     -2,-1,1,0,              /* LeftEdge, TopEdge, Frontpen, BackPen */
  412.     JAM1,2,                 /* DrawMode, Count                      */
  413.     (APTR)&minus,&plmi2     /* *XY, *NextBorder                     */
  414. };
  415.  
  416. struct Border plmi4 =
  417. {
  418.     -2,-1,1,0,              /* LeftEdge, TopEdge, Frontpen, BackPen */
  419.     JAM1,5,                 /* DrawMode, Count                      */
  420.     (APTR)&plmi_data,&plmi3 /* *XY, *NextBorder                     */
  421. };
  422.  
  423. struct Border plmi5 =
  424. {
  425.     -2,-1,2,0,               /* LeftEdge, TopEdge, Frontpen, BackPen */
  426.     JAM1,7,                  /* DrawMode, Count                      */
  427.     (APTR)&plmi_datas,&plmi4 /* *XY, *NextBorder                     */
  428. };
  429.  
  430. struct Gadget plusminus1 =
  431. {
  432.     &dn1,44,167,               /* *NextGadget, LeftEdge, TopEdge     */
  433.     15,8,GADGHCOMP,            /* Width, Height, Flags               */
  434.     GADGIMMEDIATE,             /* Activation                         */
  435.     BOOLGADGET,(APTR)&plmi5,   /* GadgetType, GadgetRender           */
  436.     NULL,                      /* SelectRender                       */
  437.     NULL,0,                    /* *GadgetText, MutualExclude         */
  438.     NULL,                      /* SpecialInfo                        */
  439.     HARMON0|PLUSMINUS,         /* GadgetID                           */
  440.     NULL                       /* UserData                           */
  441. };
  442.  
  443.  
  444. /*************************************/
  445. /*     Second amplitude gadgets       */
  446. /*************************************/
  447.  
  448. /*  Proportional gadget  */
  449.  
  450. struct PropInfo prop_info2 =
  451. {
  452.     AUTOKNOB|FREEVERT,  /* Flags                                  */
  453.     0xFFFF,0xFFFF,      /* HorizPot, VertPot                      */
  454.     0x0800,0x0800,      /* HorizBody, VertBody                    */
  455.     16,64,              /* CWidth,CHeight                         */
  456.     0x0800,0x0800,      /* HPotRes, VPotRes                       */
  457.     0,0                 /* LeftBorder, TopBorder                  */
  458. };
  459.  
  460. struct IntuiText protext2 =
  461. {
  462.     5, 2, JAM2,         /* FrontPen, BackPen, DrawMode            */
  463.     -20, 3,             /* LeftEdge, TopEdge                      */
  464.     NULL,"2:",          /* *ITextFont, *Itext                     */
  465.     NULL                /* *NextText                              */
  466. };
  467.  
  468. struct Gadget propor2 =
  469. {
  470.     &plusminus1,139,113,       /* *NextGadget, LeftEdge, TopEdge     */
  471.     14,69,GADGHCOMP|AUTOKNOB,  /* Width, Height, Flags               */
  472.     RELVERIFY|GADGIMMEDIATE,   /* Activation                         */
  473.     PROPGADGET,(APTR)&empty2,  /* GadgetType, GadgetRender           */
  474.     NULL,                      /* SelectRender                       */
  475.     (APTR)&protext2,0,         /* *GadgetText, MutualExclude         */
  476.     (APTR)&prop_info2,         /* SpecialInfo                        */
  477.     HARMON1|PROPOR,            /* GadgetID                           */
  478.     NULL                       /* UserData                           */
  479. };
  480.  
  481. /*   Up arrow gadget     */
  482.  
  483. struct Gadget up2 =
  484. {
  485.     &propor2,118,143,          /* *NextGadget, LeftEdge, TopEdge     */
  486.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  487.     GADGIMMEDIATE,             /* Activation                         */
  488.     BOOLGADGET,(APTR)&up_arr, /* GadgetType, GadgetRender           */
  489.     NULL,                      /* SelectRender                       */
  490.     NULL,0,                    /* *GadgetText, MutualExclude         */
  491.     NULL,                      /* SpecialInfo                        */
  492.     HARMON1|UPARROW,           /* GadgetID                           */
  493.     NULL                       /* UserData                           */
  494. };
  495.  
  496. /*   down arrow gadget  */
  497.  
  498. struct Gadget dn2 =
  499. {
  500.     &up2,118,152,               /* *NextGadget, LeftEdge, TopEdge     */
  501.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  502.     GADGIMMEDIATE,             /* Activation                         */
  503.     BOOLGADGET,(APTR)&dn_arr,  /* GadgetType, GadgetRender           */
  504.     NULL,                      /* SelectRender                       */
  505.     NULL,0,                    /* *GadgetText, MutualExclude         */
  506.     NULL,                      /* SpecialInfo                        */
  507.     HARMON1|DNARROW,           /* GadgetID                           */
  508.     NULL                       /* UserData                           */
  509. };
  510.  
  511. /*  Change sign gadget  */
  512.  
  513. struct Gadget plusminus2 =
  514. {
  515.     &dn2,118,167,              /* *NextGadget, LeftEdge, TopEdge     */
  516.     15,8,GADGHCOMP,            /* Width, Height, Flags               */
  517.     GADGIMMEDIATE,             /* Activation                         */
  518.     BOOLGADGET,(APTR)&plmi5,   /* GadgetType, GadgetRender           */
  519.     NULL,                      /* SelectRender                       */
  520.     NULL,0,                    /* *GadgetText, MutualExclude         */
  521.     NULL,                      /* SpecialInfo                        */
  522.     HARMON1|PLUSMINUS,         /* GadgetID                           */
  523.     NULL                       /* UserData                           */
  524. };
  525.  
  526. /*************************************/
  527. /*     Third amplitude gadgets       */
  528. /*************************************/
  529.  
  530. /*  Proportional gadget  */
  531.  
  532. struct PropInfo prop_info3 =
  533. {
  534.     AUTOKNOB|FREEVERT,  /* Flags                                  */
  535.     0xFFFF,0xFFFF,      /* HorizPot, VertPot                      */
  536.     0x0800,0x0800,      /* HorizBody, VertBody                    */
  537.     16,64,              /* CWidth,CHeight                         */
  538.     0x0800,0x0800,      /* HPotRes, VPotRes                       */
  539.     0,0                 /* LeftBorder, TopBorder                  */
  540. };
  541.  
  542. struct IntuiText protext3 =
  543. {
  544.     5, 2, JAM2,         /* FrontPen, BackPen, DrawMode            */
  545.     -20, 3,             /* LeftEdge, TopEdge                      */
  546.     NULL,"3:",          /* *ITextFont, *Itext                     */
  547.     NULL                /* *NextText                              */
  548. };
  549.  
  550. struct Gadget propor3 =
  551. {
  552.     &plusminus2,213,113,       /* *NextGadget, LeftEdge, TopEdge     */
  553.     14,69,GADGHCOMP|AUTOKNOB,  /* Width, Height, Flags               */
  554.     RELVERIFY|GADGIMMEDIATE,   /* Activation                         */
  555.     PROPGADGET,(APTR)&empty3,  /* GadgetType, GadgetRender           */
  556.     NULL,                      /* SelectRender                       */
  557.     (APTR)&protext3,0,         /* *GadgetText, MutualExclude         */
  558.     (APTR)&prop_info3,         /* SpecialInfo                        */
  559.     HARMON2|PROPOR,            /* GadgetID                           */
  560.     NULL                       /* UserData                           */
  561. };
  562.  
  563. /*   Up arrow gadget     */
  564.  
  565. struct Gadget up3 =
  566. {
  567.     &propor3,192,143,          /* *NextGadget, LeftEdge, TopEdge     */
  568.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  569.     GADGIMMEDIATE,             /* Activation                         */
  570.     BOOLGADGET,(APTR)&up_arr, /* GadgetType, GadgetRender           */
  571.     NULL,                      /* SelectRender                       */
  572.     NULL,0,                    /* *GadgetText, MutualExclude         */
  573.     NULL,                      /* SpecialInfo                        */
  574.     HARMON2|UPARROW,           /* GadgetID                           */
  575.     NULL                       /* UserData                           */
  576. };
  577.  
  578. /*   down arrow gadget  */
  579.  
  580. struct Gadget dn3 =
  581. {
  582.     &up3,192,152,               /* *NextGadget, LeftEdge, TopEdge     */
  583.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  584.     GADGIMMEDIATE,             /* Activation                         */
  585.     BOOLGADGET,(APTR)&dn_arr,  /* GadgetType, GadgetRender           */
  586.     NULL,                      /* SelectRender                       */
  587.     NULL,0,                    /* *GadgetText, MutualExclude         */
  588.     NULL,                      /* SpecialInfo                        */
  589.     HARMON2|DNARROW,           /* GadgetID                           */
  590.     NULL                       /* UserData                           */
  591. };
  592.  
  593. /*  Change sign gadget  */
  594.  
  595. struct Gadget plusminus3 =
  596. {
  597.     &dn3,192,167,              /* *NextGadget, LeftEdge, TopEdge     */
  598.     15,8,GADGHCOMP,            /* Width, Height, Flags               */
  599.     GADGIMMEDIATE,             /* Activation                         */
  600.     BOOLGADGET,(APTR)&plmi5,   /* GadgetType, GadgetRender           */
  601.     NULL,                      /* SelectRender                       */
  602.     NULL,0,                    /* *GadgetText, MutualExclude         */
  603.     NULL,                      /* SpecialInfo                        */
  604.     HARMON2|PLUSMINUS,         /* GadgetID                           */
  605.     NULL                       /* UserData                           */
  606. };
  607.  
  608. /*************************************/
  609. /*     Fourth amplitude gadgets      */
  610. /*************************************/
  611.  
  612. /*  Proportional gadget  */
  613.  
  614. struct PropInfo prop_info4 =
  615. {
  616.     AUTOKNOB|FREEVERT,  /* Flags                                  */
  617.     0xFFFF,0xFFFF,      /* HorizPot, VertPot                      */
  618.     0x0800,0x0800,      /* HorizBody, VertBody                    */
  619.     16,64,              /* CWidth,CHeight                         */
  620.     0x0800,0x0800,      /* HPotRes, VPotRes                       */
  621.     0,0                 /* LeftBorder, TopBorder                  */
  622. };
  623.  
  624. struct IntuiText protext4 =
  625. {
  626.     5, 2, JAM2,         /* FrontPen, BackPen, DrawMode            */
  627.     -20, 3,             /* LeftEdge, TopEdge                      */
  628.     NULL,"4:",          /* *ITextFont, *Itext                     */
  629.     NULL                /* *NextText                              */
  630. };
  631.  
  632. struct Gadget propor4 =
  633. {
  634.     &plusminus3,287,113,       /* *NextGadget, LeftEdge, TopEdge     */
  635.     14,69,GADGHCOMP|AUTOKNOB,  /* Width, Height, Flags               */
  636.     RELVERIFY|GADGIMMEDIATE,   /* Activation                         */
  637.     PROPGADGET,(APTR)&empty4,  /* GadgetType, GadgetRender           */
  638.     NULL,                      /* SelectRender                       */
  639.     (APTR)&protext4,0,         /* *GadgetText, MutualExclude         */
  640.     (APTR)&prop_info4,         /* SpecialInfo                        */
  641.     HARMON3|PROPOR,            /* GadgetID                           */
  642.     NULL                       /* UserData                           */
  643. };
  644.  
  645. /*   Up arrow gadget     */
  646.  
  647. struct Gadget up4 =
  648. {
  649.     &propor4,266,143,          /* *NextGadget, LeftEdge, TopEdge     */
  650.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  651.     GADGIMMEDIATE,             /* Activation                         */
  652.     BOOLGADGET,(APTR)&up_arr, /* GadgetType, GadgetRender           */
  653.     NULL,                      /* SelectRender                       */
  654.     NULL,0,                    /* *GadgetText, MutualExclude         */
  655.     NULL,                      /* SpecialInfo                        */
  656.     HARMON3|UPARROW,           /* GadgetID                           */
  657.     NULL                       /* UserData                           */
  658. };
  659.  
  660. /*   down arrow gadget  */
  661.  
  662. struct Gadget dn4 =
  663. {
  664.     &up4,266,152,              /* *NextGadget, LeftEdge, TopEdge     */
  665.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  666.     GADGIMMEDIATE,             /* Activation                         */
  667.     BOOLGADGET,(APTR)&dn_arr,  /* GadgetType, GadgetRender           */
  668.     NULL,                      /* SelectRender                       */
  669.     NULL,0,                    /* *GadgetText, MutualExclude         */
  670.     NULL,                      /* SpecialInfo                        */
  671.     HARMON3|DNARROW,           /* GadgetID                           */
  672.     NULL                       /* UserData                           */
  673. };
  674.  
  675. /*  Change sign gadget  */
  676.  
  677. struct Gadget plusminus4 =
  678. {
  679.     &dn4,266,167,              /* *NextGadget, LeftEdge, TopEdge     */
  680.     15,8,GADGHCOMP,            /* Width, Height, Flags               */
  681.     GADGIMMEDIATE,             /* Activation                         */
  682.     BOOLGADGET,(APTR)&plmi5,   /* GadgetType, GadgetRender           */
  683.     NULL,                      /* SelectRender                       */
  684.     NULL,0,                    /* *GadgetText, MutualExclude         */
  685.     NULL,                      /* SpecialInfo                        */
  686.     HARMON3|PLUSMINUS,         /* GadgetID                           */
  687.     NULL                       /* UserData                           */
  688. };
  689.  
  690. /*************************************/
  691. /*     Fifth amplitude gadgets       */
  692. /*************************************/
  693.  
  694. /*  Proportional gadget  */
  695.  
  696. struct PropInfo prop_info5 =
  697. {
  698.     AUTOKNOB|FREEVERT,  /* Flags                                  */
  699.     0xFFFF,0xFFFF,      /* HorizPot, VertPot                      */
  700.     0x0800,0x0800,      /* HorizBody, VertBody                    */
  701.     16,64,              /* CWidth,CHeight                         */
  702.     0x0800,0x0800,      /* HPotRes, VPotRes                       */
  703.     0,0                 /* LeftBorder, TopBorder                  */
  704. };
  705.  
  706. struct IntuiText protext5 =
  707. {
  708.     5, 2, JAM2,         /* FrontPen, BackPen, DrawMode            */
  709.     -20, 3,             /* LeftEdge, TopEdge                      */
  710.     NULL,"5:",          /* *ITextFont, *Itext                     */
  711.     NULL                /* *NextText                              */
  712. };
  713.  
  714. struct Gadget propor5 =
  715. {
  716.     &plusminus4,361,113,       /* *NextGadget, LeftEdge, TopEdge     */
  717.     14,69,GADGHCOMP|AUTOKNOB,  /* Width, Height, Flags               */
  718.     RELVERIFY|GADGIMMEDIATE,   /* Activation                         */
  719.     PROPGADGET,(APTR)&empty5,  /* GadgetType, GadgetRender           */
  720.     NULL,                      /* SelectRender                       */
  721.     (APTR)&protext5,0,         /* *GadgetText, MutualExclude         */
  722.     (APTR)&prop_info5,         /* SpecialInfo                        */
  723.     HARMON4|PROPOR,            /* GadgetID                           */
  724.     NULL                       /* UserData                           */
  725. };
  726.  
  727. /*   Up arrow gadget     */
  728.  
  729. struct Gadget up5 =
  730. {
  731.     &propor5,341,143,          /* *NextGadget, LeftEdge, TopEdge     */
  732.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  733.     GADGIMMEDIATE,             /* Activation                         */
  734.     BOOLGADGET,(APTR)&up_arr, /* GadgetType, GadgetRender           */
  735.     NULL,                      /* SelectRender                       */
  736.     NULL,0,                    /* *GadgetText, MutualExclude         */
  737.     NULL,                      /* SpecialInfo                        */
  738.     HARMON4|UPARROW,           /* GadgetID                           */
  739.     NULL                       /* UserData                           */
  740. };
  741.  
  742. /*   down arrow gadget  */
  743.  
  744. struct Gadget dn5 =
  745. {
  746.     &up5,340,152,               /* *NextGadget, LeftEdge, TopEdge     */
  747.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  748.     GADGIMMEDIATE,             /* Activation                         */
  749.     BOOLGADGET,(APTR)&dn_arr,  /* GadgetType, GadgetRender           */
  750.     NULL,                      /* SelectRender                       */
  751.     NULL,0,                    /* *GadgetText, MutualExclude         */
  752.     NULL,                      /* SpecialInfo                        */
  753.     HARMON4|DNARROW,           /* GadgetID                           */
  754.     NULL                       /* UserData                           */
  755. };
  756.  
  757. /*  Change sign gadget  */
  758.  
  759. struct Gadget plusminus5 =
  760. {
  761.     &dn5,340,167,              /* *NextGadget, LeftEdge, TopEdge     */
  762.     15,8,GADGHCOMP,            /* Width, Height, Flags               */
  763.     GADGIMMEDIATE,             /* Activation                         */
  764.     BOOLGADGET,(APTR)&plmi5,   /* GadgetType, GadgetRender           */
  765.     NULL,                      /* SelectRender                       */
  766.     NULL,0,                    /* *GadgetText, MutualExclude         */
  767.     NULL,                      /* SpecialInfo                        */
  768.     HARMON4|PLUSMINUS,         /* GadgetID                           */
  769.     NULL                       /* UserData                           */
  770. };
  771.  
  772. /*************************************/
  773. /*     Sixth amplitude gadgets       */
  774. /*************************************/
  775.  
  776. /*  Proportional gadget  */
  777.  
  778. struct PropInfo prop_info6 =
  779. {
  780.     AUTOKNOB|FREEVERT,  /* Flags                                  */
  781.     0xFFFF,0xFFFF,      /* HorizPot, VertPot                      */
  782.     0x0800,0x0800,      /* HorizBody, VertBody                    */
  783.     16,64,              /* CWidth,CHeight                         */
  784.     0x0800,0x0800,      /* HPotRes, VPotRes                       */
  785.     0,0                 /* LeftBorder, TopBorder                  */
  786. };
  787.  
  788. struct IntuiText protext6 =
  789. {
  790.     5, 2, JAM2,         /* FrontPen, BackPen, DrawMode            */
  791.     -20, 3,             /* LeftEdge, TopEdge                      */
  792.     NULL,"6:",          /* *ITextFont, *Itext                     */
  793.     NULL                /* *NextText                              */
  794. };
  795.  
  796. struct Gadget propor6 =
  797. {
  798.     &plusminus5,435,113,       /* *NextGadget, LeftEdge, TopEdge     */
  799.     14,69,GADGHCOMP|AUTOKNOB,  /* Width, Height, Flags               */
  800.     RELVERIFY|GADGIMMEDIATE,   /* Activation                         */
  801.     PROPGADGET,(APTR)&empty6,  /* GadgetType, GadgetRender           */
  802.     NULL,                      /* SelectRender                       */
  803.     (APTR)&protext6,0,         /* *GadgetText, MutualExclude         */
  804.     (APTR)&prop_info6,         /* SpecialInfo                        */
  805.     HARMON5|PROPOR,            /* GadgetID                           */
  806.     NULL                       /* UserData                           */
  807. };
  808.  
  809. /*   Up arrow gadget     */
  810.  
  811. struct Gadget up6 =
  812. {
  813.     &propor6,414,143,          /* *NextGadget, LeftEdge, TopEdge     */
  814.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  815.     GADGIMMEDIATE,             /* Activation                         */
  816.     BOOLGADGET,(APTR)&up_arr, /* GadgetType, GadgetRender           */
  817.     NULL,                      /* SelectRender                       */
  818.     NULL,0,                    /* *GadgetText, MutualExclude         */
  819.     NULL,                      /* SpecialInfo                        */
  820.     HARMON5|UPARROW,           /* GadgetID                           */
  821.     NULL                       /* UserData                           */
  822. };
  823.  
  824. /*   down arrow gadget  */
  825.  
  826. struct Gadget dn6 =
  827. {
  828.     &up6,414,152,               /* *NextGadget, LeftEdge, TopEdge     */
  829.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  830.     GADGIMMEDIATE,             /* Activation                         */
  831.     BOOLGADGET,(APTR)&dn_arr,  /* GadgetType, GadgetRender           */
  832.     NULL,                      /* SelectRender                       */
  833.     NULL,0,                    /* *GadgetText, MutualExclude         */
  834.     NULL,                      /* SpecialInfo                        */
  835.     HARMON5|DNARROW,           /* GadgetID                           */
  836.     NULL                       /* UserData                           */
  837. };
  838.  
  839. /*  Change sign gadget  */
  840.  
  841. struct Gadget plusminus6 =
  842. {
  843.     &dn6,414,167,              /* *NextGadget, LeftEdge, TopEdge     */
  844.     15,8,GADGHCOMP,            /* Width, Height, Flags               */
  845.     GADGIMMEDIATE,             /* Activation                         */
  846.     BOOLGADGET,(APTR)&plmi5,   /* GadgetType, GadgetRender           */
  847.     NULL,                      /* SelectRender                       */
  848.     NULL,0,                    /* *GadgetText, MutualExclude         */
  849.     NULL,                      /* SpecialInfo                        */
  850.     HARMON5|PLUSMINUS,         /* GadgetID                           */
  851.     NULL                       /* UserData                           */
  852. };
  853.  
  854. /*************************************/
  855. /*     Seventh amplitude gadgets     */
  856. /*************************************/
  857.  
  858. /*  Proportional gadget  */
  859.  
  860. struct PropInfo prop_info7 =
  861. {
  862.     AUTOKNOB|FREEVERT,  /* Flags                                  */
  863.     0xFFFF,0xFFFF,      /* HorizPot, VertPot                      */
  864.     0x0800,0x0800,      /* HorizBody, VertBody                    */
  865.     16,64,              /* CWidth,CHeight                         */
  866.     0x0800,0x0800,      /* HPotRes, VPotRes                       */
  867.     0,0                 /* LeftBorder, TopBorder                  */
  868. };
  869.  
  870. struct IntuiText protext7 =
  871. {
  872.     5, 2, JAM2,         /* FrontPen, BackPen, DrawMode            */
  873.     -20, 3,             /* LeftEdge, TopEdge                      */
  874.     NULL,"7:",          /* *ITextFont, *Itext                     */
  875.     NULL                /* *NextText                              */
  876. };
  877.  
  878. struct Gadget propor7 =
  879. {
  880.     &plusminus6,509,113,       /* *NextGadget, LeftEdge, TopEdge     */
  881.     14,69,GADGHCOMP|AUTOKNOB,  /* Width, Height, Flags               */
  882.     RELVERIFY|GADGIMMEDIATE,   /* Activation                         */
  883.     PROPGADGET,(APTR)&empty7,  /* GadgetType, GadgetRender           */
  884.     NULL,                      /* SelectRender                       */
  885.     (APTR)&protext7,0,         /* *GadgetText, MutualExclude         */
  886.     (APTR)&prop_info7,         /* SpecialInfo                        */
  887.     HARMON6|PROPOR,            /* GadgetID                           */
  888.     NULL                       /* UserData                           */
  889. };
  890.  
  891. /*   Up arrow gadget     */
  892.  
  893. struct Gadget up7 =
  894. {
  895.     &propor7,488,143,          /* *NextGadget, LeftEdge, TopEdge     */
  896.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  897.     GADGIMMEDIATE,             /* Activation                         */
  898.     BOOLGADGET,(APTR)&up_arr, /* GadgetType, GadgetRender           */
  899.     NULL,                      /* SelectRender                       */
  900.     NULL,0,                    /* *GadgetText, MutualExclude         */
  901.     NULL,                      /* SpecialInfo                        */
  902.     HARMON6|UPARROW,           /* GadgetID                           */
  903.     NULL                       /* UserData                           */
  904. };
  905.  
  906. /*   down arrow gadget  */
  907.  
  908. struct Gadget dn7 =
  909. {
  910.     &up7,488,152,               /* *NextGadget, LeftEdge, TopEdge     */
  911.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  912.     GADGIMMEDIATE,             /* Activation                         */
  913.     BOOLGADGET,(APTR)&dn_arr,  /* GadgetType, GadgetRender           */
  914.     NULL,                      /* SelectRender                       */
  915.     NULL,0,                    /* *GadgetText, MutualExclude         */
  916.     NULL,                      /* SpecialInfo                        */
  917.     HARMON6|DNARROW,           /* GadgetID                           */
  918.     NULL                       /* UserData                           */
  919. };
  920.  
  921. /*  Change sign gadget  */
  922.  
  923. struct Gadget plusminus7 =
  924. {
  925.     &dn7,488,167,              /* *NextGadget, LeftEdge, TopEdge     */
  926.     15,8,GADGHCOMP,            /* Width, Height, Flags               */
  927.     GADGIMMEDIATE,             /* Activation                         */
  928.     BOOLGADGET,(APTR)&plmi5,   /* GadgetType, GadgetRender           */
  929.     NULL,                      /* SelectRender                       */
  930.     NULL,0,                    /* *GadgetText, MutualExclude         */
  931.     NULL,                      /* SpecialInfo                        */
  932.     HARMON6|PLUSMINUS,         /* GadgetID                           */
  933.     NULL                       /* UserData                           */
  934. };
  935.  
  936. /*************************************/
  937. /*     Eighth amplitude gadgets      */
  938. /*************************************/
  939.  
  940. /*  Proportional gadget  */
  941.  
  942. struct PropInfo prop_info8 =
  943. {
  944.     AUTOKNOB|FREEVERT,  /* Flags                                  */
  945.     0xFFFF,0xFFFF,      /* HorizPot, VertPot                      */
  946.     0x0800,0x0800,      /* HorizBody, VertBody                    */
  947.     16,64,              /* CWidth,CHeight                         */
  948.     0x0800,0x0800,      /* HPotRes, VPotRes                       */
  949.     0,0                 /* LeftBorder, TopBorder                  */
  950. };
  951.  
  952. struct IntuiText protext8 =
  953. {
  954.     5, 2, JAM2,         /* FrontPen, BackPen, DrawMode            */
  955.     -20, 3,             /* LeftEdge, TopEdge                      */
  956.     NULL,"8:",          /* *ITextFont, *Itext                     */
  957.     NULL                /* *NextText                              */
  958. };
  959.  
  960. struct Gadget propor8 =
  961. {
  962.     &plusminus7,583,113,       /* *NextGadget, LeftEdge, TopEdge     */
  963.     14,69,GADGHCOMP|AUTOKNOB,  /* Width, Height, Flags               */
  964.     RELVERIFY|GADGIMMEDIATE,   /* Activation                         */
  965.     PROPGADGET,(APTR)&empty8,  /* GadgetType, GadgetRender           */
  966.     NULL,                      /* SelectRender                       */
  967.     (APTR)&protext8,0,         /* *GadgetText, MutualExclude         */
  968.     (APTR)&prop_info8,         /* SpecialInfo                        */
  969.     HARMON7|PROPOR,            /* GadgetID                           */
  970.     NULL                       /* UserData                           */
  971. };
  972.  
  973. /*   Up arrow gadget     */
  974.  
  975. struct Gadget up8 =
  976. {
  977.     &propor8,562,143,          /* *NextGadget, LeftEdge, TopEdge     */
  978.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  979.     GADGIMMEDIATE,             /* Activation                         */
  980.     BOOLGADGET,(APTR)&up_arr, /* GadgetType, GadgetRender           */
  981.     NULL,                      /* SelectRender                       */
  982.     NULL,0,                    /* *GadgetText, MutualExclude         */
  983.     NULL,                      /* SpecialInfo                        */
  984.     HARMON7|UPARROW,           /* GadgetID                           */
  985.     NULL                       /* UserData                           */
  986. };
  987.  
  988. /*   down arrow gadget  */
  989.  
  990. struct Gadget dn8 =
  991. {
  992.     &up8,562,152,               /* *NextGadget, LeftEdge, TopEdge     */
  993.     16,6,GADGHCOMP,            /* Width, Height, Flags               */
  994.     GADGIMMEDIATE,             /* Activation                         */
  995.     BOOLGADGET,(APTR)&dn_arr,  /* GadgetType, GadgetRender           */
  996.     NULL,                      /* SelectRender                       */
  997.     NULL,0,                    /* *GadgetText, MutualExclude         */
  998.     NULL,                      /* SpecialInfo                        */
  999.     HARMON7|DNARROW,           /* GadgetID                           */
  1000.     NULL                       /* UserData                           */
  1001. };
  1002.  
  1003. /*  Change sign gadget  */
  1004.  
  1005. struct Gadget plusminus8 =
  1006. {
  1007.     &dn8,562,167,              /* *NextGadget, LeftEdge, TopEdge     */
  1008.     15,8,GADGHCOMP,            /* Width, Height, Flags               */
  1009.     GADGIMMEDIATE,             /* Activation                         */
  1010.     BOOLGADGET,(APTR)&plmi5,   /* GadgetType, GadgetRender           */
  1011.     NULL,                      /* SelectRender                       */
  1012.     NULL,0,                    /* *GadgetText, MutualExclude         */
  1013.     NULL,                      /* SpecialInfo                        */
  1014.     HARMON7|PLUSMINUS,         /* GadgetID                           */
  1015.     NULL                       /* UserData                           */
  1016. };
  1017.  
  1018. struct Gadget *propadd[8]={&propor1,&propor2,&propor3,&propor4,
  1019.                        &propor5,&propor6,&propor7,&propor8};
  1020.  
  1021. /********************/
  1022. /*  Menu Structures */
  1023. /********************/
  1024.  
  1025.  
  1026. struct IntuiText stoptext = {
  1027.     0,1,JAM1,                  /* FrontPen, BackPen, DrawMode        */
  1028.     0,0,                       /* LeftEdge, TopEdge                  */
  1029.     NULL,"Stop",               /* ITextFont, *IText                  */
  1030.     NULL                       /* *NextText                          */
  1031. };
  1032.  
  1033. struct MenuItem stopgame = {
  1034.     NULL,                      /* *NextItem                          */
  1035.     0,20,80,10,                /* LeftEdge, TopEdge, Width, Height   */
  1036.     ITEMTEXT|ITEMENABLED|HIGHCOMP, /* Flags                          */
  1037.     NULL, (APTR)&stoptext,     /* MutualExclude, ItemFill            */
  1038.     NULL,NULL,                 /* Command, *SubItem                  */
  1039.     NULL                       /* NextSelect                         */
  1040. };
  1041.  
  1042. struct IntuiText hardtext = {
  1043.     0,1,JAM1,                  /* FrontPen, BackPen, DrawMode        */
  1044.     0,0,                       /* LeftEdge, TopEdge                  */
  1045.     NULL,"Start-Hard",         /* ITextFont, *IText                  */
  1046.     NULL                       /* *NextText                          */
  1047. };
  1048.  
  1049. struct MenuItem starthard = {
  1050.     &stopgame,                 /* *NextItem                          */
  1051.     0,10,80,10,                /* LeftEdge, TopEdge, Width, Height   */
  1052.     ITEMTEXT|ITEMENABLED|HIGHCOMP, /* Flags                          */
  1053.     NULL, (APTR)&hardtext,     /* MutualExclude, ItemFill            */
  1054.     NULL,NULL,                 /* Command, *SubItem                  */
  1055.     NULL                       /* NextSelect                         */
  1056. };
  1057.  
  1058. struct IntuiText easytext = {
  1059.     0,1,JAM1,                  /* FrontPen, BackPen, DrawMode        */
  1060.     0,0,                       /* LeftEdge, TopEdge                  */
  1061.     NULL,"Start-Easy",         /* ITextFont, *IText                  */
  1062.     NULL                       /* *NextText                          */
  1063. };
  1064.  
  1065. struct MenuItem starteasy = {
  1066.     &starthard,                 /* *NextItem                         */
  1067.     0,0,80,10,                 /* LeftEdge, TopEdge, Width, Height   */
  1068.     ITEMTEXT|ITEMENABLED|HIGHCOMP, /* Flags                          */
  1069.     NULL, (APTR)&easytext,     /* MutualExclude, ItemFill            */
  1070.     NULL,NULL,                 /* Command, *SubItem                  */
  1071.     NULL                       /* NextSelect                         */
  1072. };
  1073.  
  1074. struct Menu game = {
  1075.     NULL,                      /* *NextMenu                          */
  1076.     161,0,80,10,               /* LeftEdge, TopEdge, Width, Height  */
  1077.     MENUENABLED,               /* Flags                              */
  1078.     "Game",                    /* *MenuName                          */
  1079.     &starteasy                 /* First Item                         */
  1080. };
  1081.  
  1082. struct IntuiText squaretext = {
  1083.     0,1,JAM1,                  /* FrontPen, BackPen, DrawMode        */
  1084.     0,0,                       /* LeftEdge, TopEdge                  */
  1085.     NULL,"Square",             /* ITextFont, *IText                  */
  1086.     NULL                       /* *NextText                          */
  1087. };
  1088.  
  1089. struct MenuItem square = {
  1090.     NULL,                      /* *NextItem                          */
  1091.     0,30,80,10,                /* LeftEdge, TopEdge, Width, Height   */
  1092.     ITEMTEXT|ITEMENABLED|HIGHCOMP, /* Flags                          */
  1093.     NULL, (APTR)&squaretext,   /* MutualExclude, ItemFill            */
  1094.     NULL,NULL,                 /* Command, *SubItem                  */
  1095.     NULL                       /* NextSelect                         */
  1096. };
  1097.  
  1098. struct IntuiText sawtext = {
  1099.     0,1,JAM1,                  /* FrontPen, BackPen, DrawMode        */
  1100.     0,0,                       /* LeftEdge, TopEdge                  */
  1101.     NULL,"Sawtooth",           /* ITextFont, *IText                  */
  1102.     NULL                       /* *NextText                          */
  1103. };
  1104.  
  1105. struct MenuItem sawtooth = {
  1106.     &square,                   /* *NextItem                          */
  1107.     0,20,80,10,                /* LeftEdge, TopEdge, Width, Height   */
  1108.     ITEMTEXT|ITEMENABLED|HIGHCOMP, /* Flags                          */
  1109.     NULL, (APTR)&sawtext,      /* MutualExclude, ItemFill            */
  1110.     NULL,NULL,                 /* Command, *SubItem                  */
  1111.     NULL                       /* NextSelect                         */
  1112. };
  1113.  
  1114. struct IntuiText triangletext = {
  1115.     0,1,JAM1,                  /* FrontPen, BackPen, DrawMode        */
  1116.     0,0,                       /* LeftEdge, TopEdge                  */
  1117.     NULL,"Triangle",           /* ITextFont, *IText                  */
  1118.     NULL                       /* *NextText                          */
  1119. };
  1120.  
  1121. struct MenuItem triangle = {
  1122.     &sawtooth,                 /* *NextItem                          */
  1123.     0,10,80,10,                /* LeftEdge, TopEdge, Width, Height   */
  1124.     ITEMTEXT|ITEMENABLED|HIGHCOMP, /* Flags                          */
  1125.     NULL, (APTR)&triangletext, /* MutualExclude, ItemFill            */
  1126.     NULL,NULL,                 /* Command, *SubItem                  */
  1127.     NULL                       /* NextSelect                         */
  1128. };
  1129.  
  1130. struct IntuiText resettext = {
  1131.     0,1,JAM1,                  /* FrontPen, BackPen, DrawMode        */
  1132.     0,0,                       /* LeftEdge, TopEdge                  */
  1133.     NULL,"Reset",              /* ITextFont, *IText                  */
  1134.     NULL                       /* *NextText                          */
  1135. };
  1136.  
  1137. struct MenuItem resetwave = {
  1138.     &triangle,                 /* *NextItem                          */
  1139.     0,0,80,10,                 /* LeftEdge, TopEdge, Width, Height   */
  1140.     ITEMTEXT|ITEMENABLED|HIGHCOMP, /* Flags                          */
  1141.     NULL, (APTR)&resettext,    /* MutualExclude, ItemFill            */
  1142.     NULL,NULL,                 /* Command, *SubItem                  */
  1143.     NULL                       /* NextSelect                         */
  1144. };
  1145.  
  1146. struct Menu waves = {
  1147.     &game,                     /* *NextMenu                          */
  1148.     81,0,80,10,                /* LeftEdge, TopEdge, Width, Height  */
  1149.     MENUENABLED,               /* Flags                              */
  1150.     "Waveforms",               /* *MenuName                          */
  1151.     &resetwave                 /* First Item                         */
  1152. };
  1153.  
  1154. struct IntuiText quittext = {
  1155.     0,1,JAM1,                  /* FrontPen, BackPen, DrawMode        */
  1156.     0,0,                       /* LeftEdge, TopEdge                  */
  1157.     NULL,"Quit",               /* ITextFont, *IText                  */
  1158.     NULL                       /* *NextText                          */
  1159. };
  1160.  
  1161. struct MenuItem quit = {
  1162.     NULL,                      /* *NextItem                          */
  1163.     0,40,120,10,                /* LeftEdge, TopEdge, Width, Height   */
  1164.     ITEMTEXT|ITEMENABLED|HIGHCOMP, /* Flags                          */
  1165.     NULL, (APTR)&quittext,     /* MutualExclude, ItemFill            */
  1166.     NULL,NULL,                 /* Command, *SubItem                  */
  1167.     NULL                       /* NextSelect                         */
  1168. };
  1169.  
  1170. struct IntuiText fronttext = {
  1171.     0,1,JAM1,                  /* FrontPen, BackPen, DrawMode        */
  1172.     0,0,                       /* LeftEdge, TopEdge                  */
  1173.     NULL,"Screen to Front",    /* ITextFont, *IText                  */
  1174.     NULL                       /* *NextText                          */
  1175. };
  1176.  
  1177. struct MenuItem scfront = {
  1178.     &quit,                     /* *NextItem                          */
  1179.     0,30,120,10,               /* LeftEdge, TopEdge, Width, Height   */
  1180.     ITEMTEXT|ITEMENABLED|HIGHCOMP, /* Flags                          */
  1181.     NULL, (APTR)&fronttext,    /* MutualExclude, ItemFill            */
  1182.     NULL,NULL,                 /* Command, *SubItem                  */
  1183.     NULL                       /* NextSelect                         */
  1184. };
  1185.  
  1186. struct IntuiText backtext = {
  1187.     0,1,JAM1,                  /* FrontPen, BackPen, DrawMode        */
  1188.     0,0,                       /* LeftEdge, TopEdge                  */
  1189.     NULL,"Screen to Back",     /* ITextFont, *IText                  */
  1190.     NULL                       /* *NextText                          */
  1191. };
  1192.  
  1193. struct MenuItem scback = {
  1194.     &scfront,                  /* *NextItem                          */
  1195.     0,20,120,10,               /* LeftEdge, TopEdge, Width, Height   */
  1196.     ITEMTEXT|ITEMENABLED|HIGHCOMP, /* Flags                          */
  1197.     NULL, (APTR)&backtext,    /* MutualExclude, ItemFill            */
  1198.     NULL,NULL,                 /* Command, *SubItem                  */
  1199.     NULL                       /* NextSelect                         */
  1200. };
  1201.  
  1202. struct IntuiText expandtext = {
  1203.     0,1,JAM1,                  /* FrontPen, BackPen, DrawMode        */
  1204.     0,0,                       /* LeftEdge, TopEdge                  */
  1205.     NULL,"Full Scale",         /* ITextFont, *IText                  */
  1206.     NULL                       /* *NextText                          */
  1207. };
  1208.  
  1209. struct MenuItem expand = {
  1210.     &scback,                   /* *NextItem                          */
  1211.     0,10,120,10,               /* LeftEdge, TopEdge, Width, Height   */
  1212.     ITEMTEXT|ITEMENABLED|HIGHCOMP, /* Flags                          */
  1213.     NULL, (APTR)&expandtext,   /* MutualExclude, ItemFill            */
  1214.     NULL,NULL,                 /* Command, *SubItem                  */
  1215.     NULL                       /* NextSelect                         */
  1216. };
  1217.  
  1218. struct IntuiText abouttext = {
  1219.     0,1,JAM1,                  /* FrontPen, BackPen, DrawMode        */
  1220.     0,0,                       /* LeftEdge, TopEdge                  */
  1221.     NULL,"About",              /* ITextFont, *IText                  */
  1222.     NULL                       /* *NextText                          */
  1223. };
  1224.  
  1225. struct MenuItem about = {
  1226.     &expand,                   /* *NextItem                          */
  1227.     0,0,120,10,                /* LeftEdge, TopEdge, Width, Height   */
  1228.     ITEMTEXT|ITEMENABLED|HIGHCOMP, /* Flags                          */
  1229.     NULL, (APTR)&abouttext,    /* MutualExclude, ItemFill            */
  1230.     NULL,NULL,                 /* Command, *SubItem                  */
  1231.     NULL                       /* NextSelect                         */
  1232. };
  1233.  
  1234. struct Menu project = {
  1235.     &waves,                    /* *NextMenu                          */
  1236.     0,0,80,10,                 /* LeftEdge, TopEdge, Width, Height   */
  1237.     MENUENABLED,               /* Flags                              */
  1238.     "Project",                 /* *MenuName                          */
  1239.     &about                     /* First Item                         */
  1240. };
  1241.  
  1242. /****************************************/
  1243. /*     "about" requester structures     */
  1244. /****************************************/
  1245.  
  1246. struct IntuiText OK = {0,1,JAM2,5,4,NULL,"OK",NULL};
  1247.  
  1248. struct IntuiText About6 = {0,1,JAM2,8,80,NULL,
  1249.     "Click on either <OK> box to proceed",
  1250.     NULL};
  1251.     
  1252. struct IntuiText About5 = {0,1,JAM2,8,60,NULL,
  1253.     "Ames, IA, 50011, USA.      BITNET: MEYER@ALISUVAX",
  1254.     &About6};
  1255.     
  1256. struct IntuiText About4 = {0,1,JAM2,8,50,NULL,
  1257.     "W. T. Meyer, 12 Physics, Iowa State University,",
  1258.     &About5};
  1259.     
  1260. struct IntuiText About3 = {0,1,JAM2,8,30,NULL,
  1261.     "Comments and suggestions may be sent to:",
  1262.     &About4};
  1263.     
  1264. struct IntuiText About2 = {0,1,JAM2,8,20,NULL,
  1265.     "Copyright (c) 1990 by W. T. Meyer.",
  1266.     &About3};
  1267.     
  1268. struct IntuiText About1 = {0,1,JAM2,8,10,NULL,
  1269.     "WaveMaker is freely distributable for noncommercial use.",
  1270.     &About2};
  1271.     
  1272. /*************************************/
  1273. /*   "Answers" requester structures  */
  1274. /*************************************/
  1275.  
  1276. char Answers[80];
  1277.     
  1278. struct IntuiText Answer3 = {0,1,JAM2,8,30,NULL,
  1279.     "Click on either <OK> box to proceed",
  1280.     NULL};
  1281.     
  1282. struct IntuiText Answer2 = {0,1,JAM2,8,20,NULL,
  1283.     (APTR)&Answers,&Answer3};
  1284.     
  1285. struct IntuiText Answer1 = {0,1,JAM2,8,10,NULL,
  1286.     "The answers are:",&Answer2};
  1287.     
  1288. /************************************************************/
  1289. main()
  1290. /************************************************************/
  1291. {
  1292.     ULONG mclass;
  1293.     USHORT mcode,mqual,gadID,gadno,gadtyp,i;
  1294.     USHORT amptopot();
  1295.     unsigned seed;
  1296.     LONG pottoamp(),MakeWave();
  1297.     SHORT potsign,keyraw,keyup,keyrepeat;
  1298.     struct Gadget *mgadget;
  1299.     struct PropInfo *propinfo;
  1300.     VOID OpenLibs(),Cleanup(),MakeDisplay(),MakeSin(),MakePalette();
  1301.     VOID AmpsUpDate(),PropUpdate(),DrawBoxes(),DrawUser();
  1302.     VOID SoundOn(),SoundOff(),MenuSetup(),DoMenu(),OpenAudio();
  1303.     VOID Update(),InitArrays();
  1304.     
  1305. /*  Initialization  */
  1306.  
  1307.     OpenLibs();
  1308.     
  1309.     OpenAudio();
  1310.     
  1311.     seed = (unsigned)time(NULL);
  1312.     srand(seed);
  1313.     
  1314.     MakeSin();
  1315.     
  1316.     for (i=0;i<8;++i) amps[i]=0;
  1317.     
  1318.     InitArrays();
  1319.  
  1320.     MakeDisplay();
  1321.     
  1322.     SetMenuStrip(Window,&project);
  1323.     
  1324.   
  1325.  /*  Set up an IDCMP Read Loop  */
  1326.  
  1327.     for(;;) {
  1328.     Wait(1<<Window->UserPort->mp_SigBit);
  1329.  
  1330.     while((mesg=(struct IntuiMessage *)
  1331.        GetMsg(Window->UserPort))!=NULL)  /* Wait for IntuiMessage    */
  1332.     {
  1333.         mclass = mesg->Class;        /* Run through all of them  */
  1334.         mcode = mesg->Code;          /* Local copies of variables*/
  1335.         mqual = mesg->Qualifier;
  1336.         mgadget =(struct Gadget *)mesg->IAddress;
  1337.         gadID = mgadget->GadgetID;
  1338.                 switch(mclass)
  1339.         {
  1340.            case CLOSEWINDOW: 
  1341.            {
  1342.              Cleanup();
  1343.             Exit(TRUE);
  1344.             break;
  1345.            }
  1346.            case REFRESHWINDOW:
  1347.            {
  1348.             DrawBoxes();
  1349.             Update(0);
  1350.             break;
  1351.            }
  1352.            case MENUPICK:
  1353.            {
  1354.             DoMenu(mcode);
  1355.             break;
  1356.            }
  1357.            case GADGETDOWN:
  1358.            {
  1359.             gadno = gadID&0x7;
  1360.             gadtyp = gadID&0x38;
  1361.             switch(gadtyp)
  1362.             {
  1363.               case UPARROW:
  1364.                 if (amps[gadno]>=0) ++amps[gadno];
  1365.                 else --amps[gadno];
  1366.                 Update(gadno);
  1367.                 ModifyProp(propadd[gadno],Window,NULL,
  1368.                   FREEVERT|AUTOKNOB,0xFFFF,
  1369.                   amptopot(amps[gadno]),0x0800,0x0800);
  1370.                 break;
  1371.               case DNARROW:
  1372.                 if (amps[gadno]>=0) --amps[gadno];
  1373.                 else ++amps[gadno];
  1374.                 Update(gadno);
  1375.                 ModifyProp(propadd[gadno],Window,NULL,
  1376.                   FREEVERT|AUTOKNOB,0xFFFF,
  1377.                   amptopot(amps[gadno]),0x0800,0x0800);
  1378.                 break;
  1379.               case PLUSMINUS:
  1380.                 amps[gadno]=-amps[gadno];
  1381.                 Update(gadno);
  1382.                 break;
  1383.               case PROPOR:
  1384.                 break;
  1385.                   }
  1386.               break;
  1387.            }
  1388.            case GADGETUP:
  1389.            {
  1390.             gadno = gadID&0x7;
  1391.             gadtyp = gadID&0x38;
  1392.             switch(gadtyp)
  1393.             {
  1394.               case UPARROW:
  1395.                 break;
  1396.               case DNARROW:
  1397.                 break;
  1398.               case PLUSMINUS:
  1399.                 break;
  1400.               case PROPOR:
  1401.                 potsign=1;
  1402.                 if (amps[gadno]<0) potsign=-1;
  1403.                 propinfo=mgadget->SpecialInfo;
  1404.                 amps[gadno]=pottoamp(propinfo->VertPot,
  1405.                     potsign);
  1406.                 Update(gadno);
  1407.                 break;
  1408.               }
  1409.               break;
  1410.            }
  1411.            case RAWKEY:
  1412.                 keyrepeat=mqual&IEQUALIFIER_REPEAT;
  1413.             keyraw = mcode&0x7F;
  1414.             keyup = mcode&0x80;
  1415.             if (keyup==0&&!keyrepeat) 
  1416.                 SoundOn(keyraw,usersound);
  1417.             if (keyup!=0) SoundOff(keyraw);
  1418.             break;
  1419.         }
  1420.         ReplyMsg(mesg);              /* Give message back        */
  1421.     }
  1422.     }
  1423. }
  1424.  
  1425. /**************************************************************/     
  1426. VOID OpenLibs()
  1427.     
  1428. /* Open all required libraries */
  1429.  
  1430. {
  1431. /*  ==Open Intuition... */
  1432.  
  1433.        IntuitionBase = (struct IntuitionBase *)
  1434.               OpenLibrary("intuition.library",INTUITION_REV);
  1435.        if(IntuitionBase == NULL) 
  1436.       ErrExit(INTUITION_FAIL);
  1437.  
  1438. /*  ==Open Graphics...  */
  1439.         GfxBase = (struct GfxBase *)
  1440.           OpenLibrary("graphics.library",GRAPHICS_REV);
  1441.     if(GfxBase == NULL)
  1442.             ErrExit(GRAPHICS_FAIL);
  1443.  
  1444. }  
  1445.         
  1446. /*******************************************************************/
  1447. VOID Cleanup()
  1448. /* ======Close down the window, the screen, and the libraries====== */
  1449. {
  1450.     ClearMenuStrip(Window);
  1451.     CloseWindow(Window);  
  1452.       CloseScreen(Screen);
  1453.     FreeMem(refsound,516);
  1454.     FreeMem(usersound,516);
  1455.     CloseDevice(ioa);
  1456.     CloseLibrary(GfxBase);
  1457.       CloseLibrary(IntuitionBase);
  1458.       exit(NULL);
  1459. }
  1460.  
  1461. /******************************************************************/
  1462. VOID ErrExit(SHORT errno)
  1463.  
  1464. /*  This routine gets called if a fatal error occurs.  It ends    */
  1465. /*  the program gracefully by closing all of the resources opened */
  1466. /*  to that point.                                                */
  1467.  
  1468. {
  1469.     char *ErrMess[]={"Successful Completion\n",
  1470.              "Unable to open Intuition.library\n",
  1471.                  "Unable to open Graphics.library\n",
  1472.              "Unable to allocate port PN\n",
  1473.              "Unable to allocate port P0\n",
  1474.              "Unable to allocate audio memory\n",
  1475.              "Unable to open audio device\n",
  1476.              "Unable to allocate usersound\n",
  1477.              "Unable to allocate refsound\n",
  1478.              "Unable to open Screen\n",
  1479.              "Unable to open Window\n"};
  1480.     
  1481.     printf(ErrMess[errno]);    
  1482.     
  1483.     switch(errno)            /* Yes, the fall-through is deliberate */
  1484.     {
  1485.     case SUCCESS:
  1486.         ClearMenuStrip(Window);
  1487.         CloseWindow(Window);
  1488.     case WINDOW_FAIL:
  1489.         CloseScreen(Screen);
  1490.     case SCREEN_FAIL:
  1491.         FreeMem(refsound,516);
  1492.     case REFSOUND_FAIL:
  1493.         FreeMem(usersound,516);
  1494.     case USERSOUND_FAIL:
  1495.         CloseDevice(ioa);
  1496.     case AUDIOALLOC_FAIL:
  1497.     case AUDIO_FAIL:
  1498.     case PORTP0_FAIL:
  1499.     case PORTPN_FAIL:
  1500.         CloseLibrary(GfxBase);
  1501.     case GRAPHICS_FAIL:
  1502.         CloseLibrary(IntuitionBase);
  1503.     case INTUITION_FAIL:
  1504.         break;
  1505.     }
  1506.     Exit(FALSE);
  1507. }
  1508.  
  1509. /********************************************************************/
  1510. VOID Update(USHORT gadno)
  1511.  
  1512. /*  Update the amplitudes and screen when one amplitude has been changed */
  1513.  
  1514. {
  1515.     VOID AmpsUpdate(),DrawUser();
  1516.     LONG MakeWave();
  1517.     
  1518.     if (amps[gadno]>127) amps[gadno]=127;
  1519.     if (amps[gadno]<-127) amps[gadno]=-127;
  1520.     AmpsUpdate();
  1521.     maxuser=MakeWave(amps,waveform,usersound);
  1522.     DrawUser();
  1523. }
  1524.  
  1525. /*************************************************************/
  1526. VOID DoMenu(USHORT mcode)
  1527.  
  1528. /*  Does the right thing when a menu option is chosen */
  1529.  
  1530. {
  1531. #define PROJECT_MENU 0
  1532. #define WAVE_MENU    1
  1533. #define GAME_MENU    2
  1534.  
  1535. #define ABOUT        0
  1536. #define FULLSCALE    1
  1537. #define SCREENBACK   2
  1538. #define SCREENFRONT  3
  1539. #define QUIT         4
  1540.  
  1541. #define START_EASY   0
  1542. #define START_HARD   1
  1543. #define STOP         2
  1544.  
  1545. switch(MENUNUM(mcode))
  1546. {
  1547.     LONG peak;
  1548.     SHORT i,item,scale;
  1549.     LONG temp,AddWaves(),randamp(),checkval(),MakeWave();
  1550.     VOID AmpsUpdate(),PropUpdate(),AutoRequest(),
  1551.         DrawUser(),Cleanup(),rescale();
  1552.     static SHORT canned[4][8]={{  0,  0,  0,  0,  0,  0,  0,  0},
  1553.                                {108,  0,-12,  0,  4,  0, -2,  0},
  1554.                            { 74,-38, 24,-20, 14,-12, 10, -9},
  1555.                            {124,  0, 41,  0, 25,  0, 18,  0}};
  1556.  
  1557.                    
  1558.     
  1559.     case PROJECT_MENU:
  1560.         switch (ITEMNUM(mcode))
  1561.         {
  1562.             case ABOUT:
  1563.             {
  1564.                 AutoRequest(Window,&About1,&OK,&OK,
  1565.                    NULL,NULL,500,130);
  1566.                 break;
  1567.             }
  1568.             case FULLSCALE:
  1569.             {
  1570.                     if ((peak=checkval(maxuser,amps))!=0) 
  1571.                    rescale(peak,amps);
  1572.                 maxuser=AddWaves(amps,waveform,
  1573.                     usersound)>>15;
  1574.                 AmpsUpdate();
  1575.                 PropUpdate();
  1576.                 DrawUser();
  1577.                 break;
  1578.             }
  1579.             case SCREENBACK:
  1580.             {
  1581.                 ScreenToBack(Screen);
  1582.                 break;
  1583.             }
  1584.             case SCREENFRONT:
  1585.             {
  1586.                 ScreenToFront(Screen);
  1587.                 break;
  1588.             }
  1589.             case QUIT:
  1590.             {
  1591.                 Cleanup();
  1592.                 Exit(TRUE);
  1593.             }
  1594.         }
  1595.         break;
  1596.     case WAVE_MENU:
  1597.         item = ITEMNUM(mcode);
  1598.         for (i=0; i<8; ++i)
  1599.         {
  1600.             amps[i] = canned[item][i];
  1601.         }
  1602.         AmpsUpdate();
  1603.         PropUpdate();
  1604.         maxuser=MakeWave(amps,waveform,usersound);
  1605.         DrawUser();
  1606.         break;
  1607.     case GAME_MENU:
  1608.         switch (ITEMNUM(mcode))
  1609.         {
  1610.             case START_EASY:
  1611.                 gameon = YES;
  1612.                 for (i=0; i<4; i++)
  1613.                 {
  1614.                     refamps[i] = randamp();
  1615.                 }
  1616.                 for (i=4;i<8;i++) refamps[i]=0;
  1617.                 maxref=MakeWave(refamps,refform,refsound);
  1618.                     if (maxref==0) maxref=1;
  1619.                 scale=maxamp/maxref;
  1620.                 for (i=0;i<4;++i)
  1621.                 {
  1622.                     temp=refamps[i]*scale;
  1623.                     refamps[i]=temp>>7;
  1624.                 }
  1625.                 maxref=AddWaves(refamps,refform,
  1626.                     refsound)>>15;
  1627.                 for (i=0; i<513; ++i)
  1628.                 {
  1629.                     refwave[i][1]=((129-refform[i])*48)>>7;
  1630.                 }
  1631.                 DrawUser();
  1632.                 break;
  1633.             case START_HARD:
  1634.                 gameon = YES;
  1635.                 for (i=0; i<8; i++)
  1636.                 {
  1637.                     refamps[i] = randamp();
  1638.                 }
  1639.                 maxref=MakeWave(refamps,refform,refsound);
  1640.                     if (maxref==0) maxref=1;
  1641.                 scale=maxamp/maxref;
  1642.                 for (i=0;i<8;++i)
  1643.                 {
  1644.                     temp=refamps[i]*scale;
  1645.                     refamps[i]=temp>>7;
  1646.                 }
  1647.                 maxref=AddWaves(refamps,refform,
  1648.                     refsound)>>15;
  1649.                 for (i=0; i<513; ++i)
  1650.                 {
  1651.                     refwave[i][1]=((129-refform[i])*48)>>7;
  1652.                 }
  1653.                 DrawUser();
  1654.                 break;
  1655.             case STOP:
  1656.                 gameon = NO;
  1657.                 sprintf(Answers,
  1658.                  "%6d %6d %6d %6d %6d %6d %6d %6d",
  1659.                  refamps[0],refamps[1],refamps[2],
  1660.                  refamps[3],refamps[4],refamps[5],
  1661.                  refamps[6],refamps[7]);
  1662.                 AutoRequest(Window,&Answer1,&OK,&OK,
  1663.                    NULL,NULL,620,80);
  1664.                 DrawUser();
  1665.                 break;
  1666.         }
  1667.         break;
  1668. }
  1669. }
  1670.  
  1671. /*************************************************************/
  1672. VOID MakeDisplay()
  1673.  
  1674. /*  Opens the screen and window, and creates the initial display  */
  1675.  
  1676. {    
  1677.     VOID DrawBoxes();
  1678.         
  1679.     Screen = (struct Screen *)MakeScreen();
  1680.     if (Screen == NULL) ErrExit(SCREEN_FAIL);
  1681.     
  1682.     Window = (struct Window *)MakeWindow();
  1683.     if (Window == NULL) ErrExit(WINDOW_FAIL);
  1684.     
  1685.     MakePalette(Window);
  1686.     
  1687.     DrawBoxes();
  1688. }
  1689.  
  1690. /*************************************************************/
  1691. VOID DrawBoxes()
  1692.  
  1693. /*  Draws the waveform display area and the boxes around the */
  1694. /*  numerical display                                        */
  1695. {
  1696.     SHORT i;
  1697.     static SHORT boxx[8]={34,108,182,256,330,404,478,552};
  1698.     
  1699. /*  Draw waveform display area  */
  1700.     rport = Window->RPort;
  1701.     SetAPen(rport,5);
  1702.     RectFill(rport,40,14,601,109);
  1703.     SetAPen(rport,2);
  1704.     RectFill(rport,44,12,597,111);
  1705.     SetAPen(rport,1);
  1706.     RectFill(rport,64,14,577,109);
  1707.     SetAPen(rport,3);
  1708.     RectFill(rport,64,61,577,61);
  1709.  
  1710. /*  Draw boxes for digital display of amplitudes   */
  1711.     for (i=0;i<8;++i)
  1712.     {
  1713.         DrawBorder(rport,&brdi1,boxx[i],188);
  1714.         sprintf(textbuf,"%5d",amps[i]);
  1715.         PrintIText(rport,&textamp,boxx[i],188);
  1716.     }
  1717. }
  1718.  
  1719. /****************************************************************/
  1720. VOID InitArrays()    
  1721. /*  Initialize data arrays for waveform displays  */
  1722. {
  1723.         SHORT i;
  1724.     
  1725.     for (i=0;i<513;++i)
  1726.     {
  1727.         userwave[i][0]=refwave[i][0]=i;
  1728.         userwave[i][1]=refwave[i][1]=0;
  1729.     }
  1730. }
  1731.  
  1732. /***************************************************************/
  1733. VOID MakePalette(Window)
  1734.  
  1735. /*  Sets the color palette  */
  1736.  
  1737. {
  1738.     ViewPort = (struct ViewPort *)ViewPortAddress(Window);
  1739.  
  1740. /*  ==Set palette...  */
  1741.  
  1742.      SetRGB4(ViewPort, 0,  7,  4,  3);    /* Dark beige  */
  1743.     SetRGB4(ViewPort, 1, 15, 12,  9);    /* Light beige */
  1744.     SetRGB4(ViewPort, 2,  5,  1,  0);    /* Brown       */
  1745.     SetRGB4(ViewPort, 3,  4,  4,  4);    /* dark  gray  */
  1746.     SetRGB4(ViewPort, 4, 11,  0,  0);    /* Red         */
  1747.     SetRGB4(ViewPort, 5, 13, 10,  0);    /* Yellow      */
  1748.     SetRGB4(ViewPort, 6,  6,  8,  2);    /* Green       */
  1749.     SetRGB4(ViewPort, 7,  0,  0,  0);    /* Black       */    
  1750. }
  1751.  
  1752. /*****************************************************************/
  1753. MakeScreen()
  1754.  
  1755. {
  1756. /*  ==Open a custom screen...  */
  1757.  
  1758.        struct NewScreen NewScreen =
  1759.        {    0, 0, 640, 200,      /* LeftEdge, TopEdge, Width, Height */
  1760.         3, 0x00, 0x01,       /* Depth, DetailPen, BlockPen       */
  1761.         HIRES,CUSTOMSCREEN,  /* ViewModes, Type                  */
  1762.         NULL,"WaveScreen",NULL,/* Font, DefaultTitle, Gadgets    */
  1763.         NULL                 /* CustomBitMap                     */
  1764.     };
  1765.   
  1766.        return(OpenScreen(&NewScreen));
  1767. }
  1768.  
  1769. /******************************************************************/
  1770. MakeWindow()
  1771.  
  1772. /*  This function initializes the NewWindow structure and opens 
  1773.     the window */
  1774.  
  1775. {
  1776.     struct NewWindow NewWindow;
  1777.      ULONG flags;
  1778.     USHORT iflags;
  1779.     
  1780. /*  ==Open the window...  */
  1781.  
  1782.        flags=SMART_REFRESH|WINDOWSIZING|WINDOWDRAG|WINDOWCLOSE;
  1783.        iflags=CLOSEWINDOW|REFRESHWINDOW|GADGETDOWN|GADGETUP|RAWKEY|
  1784.         MENUPICK;
  1785.         NewWindow.LeftEdge=0;
  1786.         NewWindow.TopEdge=0;
  1787.         NewWindow.Width=640;
  1788.         NewWindow.Height=200;
  1789.         NewWindow.DetailPen=0x00;
  1790.         NewWindow.BlockPen=0x01;
  1791.         NewWindow.Flags=flags;
  1792.         NewWindow.IDCMPFlags=iflags;
  1793.         NewWindow.FirstGadget=&plusminus8;
  1794.         NewWindow.CheckMark=NULL;
  1795.        NewWindow.Title="WaveMaker 1.1";
  1796.          NewWindow.Screen=Screen;
  1797.         NewWindow.BitMap=NULL;
  1798.         NewWindow.MinWidth=16;
  1799.         NewWindow.MinHeight=16;
  1800.         NewWindow.MaxWidth=640;
  1801.         NewWindow.MaxHeight=200;
  1802.         NewWindow.Type=CUSTOMSCREEN;
  1803.     
  1804.         return(OpenWindow(&NewWindow));
  1805.     
  1806. }
  1807.  
  1808. /*********************************************************************/
  1809. VOID MakeSin()
  1810.  
  1811. /*  Initialize the sine wave arrays for all eight frequencies.        */
  1812. /*  This saves a lot of time later.                                   */
  1813.  
  1814. {
  1815.     SHORT i,j,k;
  1816.     FLOAT step;
  1817.     
  1818.     step = 6.283185/512.0;
  1819.     for (i=0; i<513; ++i) sinewave[0][i]=sin(i*step)*0x7FFF;
  1820.     for (j=1; j<8; ++j)
  1821.     {
  1822.         for (i=0; i<513; ++i)
  1823.         {
  1824.             k=((j+1)*i)%512;
  1825.             sinewave[j][i]=sinewave[0][k];
  1826.         }
  1827.     }
  1828. }
  1829.  
  1830. /****************************************************************/
  1831. VOID OpenAudio()
  1832.  
  1833. /*  Alloc and open the audio device and initialize the structures */
  1834.  
  1835. {
  1836.     char *portstring[]={"aud0","aud1","aud2","aud3","aud4"};
  1837.     SHORT i;
  1838.     static SHORT chanbits[4]={1,2,4,8};
  1839.     
  1840. /*  allocate memory for IOAudio structures   */
  1841.  
  1842.     ioa=(struct IOAudio *)AllocMem((NBR_IOA_STRUCTS*sizeof(*ioa)),
  1843.         MEMF_PUBLIC|MEMF_CLEAR);
  1844.     if (ioa==NULL) ErrExit(AUDIOALLOC_FAIL);
  1845.     
  1846. /*  set the IOAudio structure pointers  */
  1847.  
  1848.     finish = &ioa[5];
  1849.     audio = &ioa[0];
  1850.     
  1851. /* open the audio device   */
  1852.  
  1853.     ioa->ioa_Request.io_Message.mn_Node.ln_Pri=10;
  1854.     ioa->ioa_Data=&sunit;
  1855.     ioa->ioa_Length=(ULONG)sizeof(sunit);
  1856.     ioa->ioa_Request.io_Message.mn_ReplyPort=CreatePort("aud0",0);
  1857.     if (ioa->ioa_Request.io_Message.mn_ReplyPort==NULL)
  1858.          ErrExit(PORTP0_FAIL);
  1859.     if((OpenDevice(AUDIONAME,0,ioa,0))!=NULL) ErrExit(AUDIO_FAIL);
  1860.     
  1861. /*  set up the finish structure  */
  1862.  
  1863.     *finish = *ioa;
  1864.     finish->ioa_Request.io_Flags = IOF_QUICK;
  1865.     finish->ioa_Request.io_Command = ADCMD_FINISH;
  1866.     
  1867. /*  set up the audio channels and initialize them  */
  1868.  
  1869.     for (i=0; i<4; ++i)
  1870.     {
  1871.         audchan[i]=&ioa[i+1];
  1872.         *audchan[i]=*ioa;
  1873.         if ((audchan[i]->ioa_Request.io_Message.mn_ReplyPort =
  1874.           CreatePort(portstring[i],0))==NULL) ErrExit(PORTPN_FAIL);
  1875.         audchan[i]->ioa_Request.io_Command=CMD_WRITE;
  1876.         audchan[i]->ioa_Request.io_Flags=IOF_QUICK|ADIOF_PERVOL;
  1877.         audchan[i]->ioa_Cycles=0;
  1878.         audchan[i]->ioa_Length=128;
  1879.         audchan[i]->ioa_Request.io_Unit=chanbits[i];
  1880.     }
  1881.     if((usersound = (BYTE *)AllocMem(516, MEMF_CHIP))==0) 
  1882.         ErrExit(USERSOUND_FAIL);
  1883.     if((refsound = (BYTE *)AllocMem(516, MEMF_CHIP))==0)
  1884.         ErrExit(REFSOUND_FAIL);
  1885. }
  1886.         
  1887. /****************************************************************/
  1888. VOID AmpsUpdate()
  1889.  
  1890. /*  Update the numerical amplitude displays   */
  1891.  
  1892. {
  1893.     SHORT i;
  1894.     SHORT boxx[8]={34,108,182,256,330,404,478,552};
  1895.     
  1896.     for (i=0;i<8;i++)
  1897.     {
  1898.         sprintf(textbuf,"%5d",amps[i]);
  1899.         PrintIText(rport,&textamp,boxx[i],188);
  1900.     }
  1901. }
  1902.  
  1903. /****************************************************************/
  1904. VOID PropUpdate()
  1905.  
  1906. /*  Update the proportional gadgets after a rescaling  */
  1907.  
  1908. {
  1909.     USHORT temp;
  1910.     temp=amptopot(amps[7]);
  1911.     ModifyProp(&propor8,Window,NULL,FREEVERT|AUTOKNOB,0xFFFF,
  1912.         temp,0x0800,0x0800);
  1913.     temp=amptopot(amps[6]);
  1914.     ModifyProp(&propor7,Window,NULL,FREEVERT|AUTOKNOB,0xFFFF,
  1915.         temp,0x0800,0x0800);
  1916.     temp=amptopot(amps[5]);
  1917.     ModifyProp(&propor6,Window,NULL,FREEVERT|AUTOKNOB,0xFFFF,
  1918.         temp,0x0800,0x0800);
  1919.     temp=amptopot(amps[4]);
  1920.     ModifyProp(&propor5,Window,NULL,FREEVERT|AUTOKNOB,0xFFFF,
  1921.         temp,0x0800,0x0800);
  1922.     temp=amptopot(amps[3]);
  1923.     ModifyProp(&propor4,Window,NULL,FREEVERT|AUTOKNOB,0xFFFF,
  1924.         temp,0x0800,0x0800);
  1925.     temp=amptopot(amps[2]);
  1926.     ModifyProp(&propor3,Window,NULL,FREEVERT|AUTOKNOB,0xFFFF,
  1927.         temp,0x0800,0x0800);
  1928.     temp=amptopot(amps[1]);
  1929.     ModifyProp(&propor2,Window,NULL,FREEVERT|AUTOKNOB,0xFFFF,
  1930.         temp,0x0800,0x0800);
  1931.     temp=amptopot(amps[0]);
  1932.     ModifyProp(&propor1,Window,NULL,FREEVERT|AUTOKNOB,0xFFFF,
  1933.         temp,0x0800,0x0800);
  1934. }
  1935.  
  1936. /****************************************************************/
  1937. USHORT amptopot(amp)
  1938.  
  1939. /* Convert an amplitude to an integer to put in the proportional */
  1940. /* gadget's VertPot value.                                       */
  1941.  
  1942. LONG amp;
  1943. {
  1944.     USHORT temp;
  1945.     
  1946.     temp = (127-abs(amp))<<9;
  1947.     return(temp);
  1948. }
  1949.  
  1950. /****************************************************************/
  1951. LONG pottoamp(pot,potsign)
  1952.  
  1953. /* Converts a proportional gadget's VertPot value to an amplitude  */
  1954.  
  1955. USHORT pot;
  1956. SHORT potsign;
  1957. {
  1958.     LONG temp;
  1959.     temp = (127-(pot>>9))*potsign;
  1960.     return(temp);
  1961. }
  1962.  
  1963. /****************************************************************/
  1964. LONG AddWaves(LONG ampl[],BYTE wf[],UBYTE *ws)
  1965.  
  1966. /*  Create the compound waveform by adding the harmonics.  This      */
  1967. /*  routine is a likely candidate for future conversion to assembler */
  1968. /*  to speed things up.                                              */
  1969.  
  1970. {
  1971.     SHORT i,j;
  1972.     LONG wavebuff[513];
  1973.     LONG maxval,minval;
  1974.     
  1975.     for (j=0;j<513;++j) wavebuff[j]=ampl[0]*sinewave[0][j];
  1976.     for (i=1;i<8;++i)
  1977.     {
  1978.         for (j=0;j<513;++j)
  1979.         {
  1980.             wavebuff[j]=wavebuff[j]+ampl[i]*sinewave[i][j];
  1981.         }
  1982.     }
  1983.     maxval=minval=0;
  1984.     for (j=0;j<513;++j)
  1985.     {
  1986.          wf[j]=wavebuff[j]>>15;
  1987.          ws[j/4]=wf[j];
  1988.          if (wavebuff[j]>maxval) maxval=wavebuff[j];
  1989.          if (wavebuff[j]<minval) minval=wavebuff[j];
  1990.     }
  1991.     if (abs(minval)>maxval) maxval=abs(minval);
  1992.     return(maxval);
  1993. }
  1994.  
  1995. /*****************************************************************/
  1996. LONG MakeWave(LONG ampl[],BYTE wf[],UBYTE *ws)
  1997.  
  1998. /*  Makes the compound waveform (via AddWaves) and checks that it */
  1999. /*  is not off scale.  If it is, it rescales.                     */
  2000. {
  2001.     LONG peak;
  2002.     LONG maxnow;
  2003.     LONG AddWaves();
  2004.     LONG checkval();
  2005.     VOID rescale();
  2006.     
  2007.     maxnow=AddWaves(ampl,wf,ws)>>15;
  2008.     if ((peak=checkval(maxnow,ampl))>127)
  2009.     {
  2010.         rescale(peak,ampl);
  2011.         maxnow=AddWaves(ampl,wf,ws)>>15;
  2012.     }
  2013.     return(maxnow);
  2014. }
  2015.  
  2016. /******************************************************************/
  2017. LONG checkval(LONG maxval,LONG ampl[])
  2018.  
  2019. /*  Checks maxval, and all of the amps[i] to find the largest     */
  2020. /*  in absolute value.                                            */
  2021.  
  2022. {
  2023.     SHORT i;
  2024.     LONG temp;
  2025.     
  2026.     temp = maxval;
  2027.     for (i=0; i<8; ++i)
  2028.     {
  2029.         if (abs(ampl[i])>temp) temp=abs(ampl[i]);
  2030.     }
  2031.     return(temp);
  2032. }
  2033.  
  2034. /******************************************************************/
  2035. VOID rescale(LONG peak,LONG ampl[])
  2036.  
  2037. /*  rescale to make the amplitude a high as possible without having */
  2038. /*  any ampltiude or the compound wave exceed 127 in absolute value */
  2039. {
  2040.     extern LONG maxamp;
  2041.     SHORT scale,i;
  2042.     LONG temp;
  2043.     
  2044.     scale=maxamp/peak;
  2045.     for (i=0;i<8;++i)         /* Be careful not to lose bits */
  2046.     {
  2047.         temp=ampl[i]*scale;
  2048.         ampl[i]=temp>>7;
  2049.     }
  2050. }
  2051. /***********************************************************************/
  2052. VOID DrawUser()
  2053.  
  2054. /*  Draws the compound waveform in the display area.  */
  2055.  
  2056. {
  2057.     SHORT i;
  2058.     for (i=0;i<513;++i) userwave[i][1]=((129-waveform[i])*48)>>7;
  2059.     SetAPen(rport,1);
  2060.     RectFill(rport,64,14,577,109);
  2061.     SetAPen(rport,3);
  2062.     RectFill(rport,64,61,577,61);
  2063.     if (gameon) DrawBorder(rport,&RWave_brd5,0,0);
  2064.     DrawBorder(rport,&UWave_brd5,0,0);
  2065. }
  2066.  
  2067. /************************************************************/
  2068. VOID SoundOn(SHORT key,UBYTE *ws)
  2069.  
  2070. /*  Start a sound channel   */
  2071.  
  2072. {
  2073.     UWORD tone;
  2074.     UWORD periods[16]={452, 428, 404, 381, 359, 339, 320, 302,
  2075.                    285, 269, 254, 240, 226, 214, 202, 190};
  2076.     SHORT channo,FreeChan();
  2077.     
  2078.     switch (key)
  2079.     {
  2080.         case 0x31: {tone=periods[0]; break;}
  2081.         case 0x32: {tone=periods[1]; break;}
  2082.         case 0x22: {tone=periods[2]; break;}
  2083.         case 0x33: {tone=periods[3]; break;}
  2084.         case 0x23: {tone=periods[4]; break;}
  2085.         case 0x34: {tone=periods[5]; break;}
  2086.         case 0x35: {tone=periods[6]; break;}
  2087.         case 0x25: {tone=periods[7]; break;}
  2088.         case 0x36: {tone=periods[8]; break;}
  2089.         case 0x26: {tone=periods[9]; break;}
  2090.         case 0x37: {tone=periods[10]; break;}
  2091.         case 0x27: {tone=periods[11]; break;}
  2092.         case 0x38: {tone=periods[12]; break;}
  2093.         case 0x39: {tone=periods[13]; break;}
  2094.         case 0x29: {tone=periods[14]; break;}
  2095.         case 0x3A: {tone=periods[15]; break;}
  2096.         default: tone=0;
  2097.     }
  2098.     if (((channo = FreeChan())<4)&(key<64))
  2099.     {
  2100.         audchan[channo]->ioa_Period=tone;
  2101.         if(tone==0) audchan[channo]->ioa_Volume=0;
  2102.         else audchan[channo]->ioa_Volume=64;
  2103.         audchan[channo]->ioa_Data=(UBYTE *)ws;
  2104.         audiochan[key]=channo;
  2105.         WaitIO(audchan[channo]);
  2106.         BeginIO(audchan[channo]);
  2107.     }
  2108. }
  2109.  
  2110. /************************************************************/
  2111. VOID SoundOff(SHORT key)
  2112.  
  2113. /*  Stop a sound channel  */
  2114.  
  2115. {
  2116.     SHORT channo;
  2117.     static SHORT chanbits[4]={1,2,4,8};
  2118.     
  2119.     channo = audiochan[key];
  2120.     audiochan[key]=-1;
  2121.     if ((channo>=0)&(key<64))
  2122.     {
  2123.         finish->ioa_Request.io_Unit=chanbits[channo];
  2124.         BeginIO(finish);
  2125.         WaitIO(audchan[channo]);
  2126.         waiting[channo]=NO;
  2127.     }
  2128. }
  2129.  
  2130. /************************************************************/
  2131. LONG randamp()
  2132.  
  2133. /*  Picks a random amplitude (for the game mode)  */
  2134.  
  2135. {
  2136.     LONG temp;
  2137.     
  2138.     temp=(rand()&0xFF)-127;
  2139.     if (temp==128) temp=127;
  2140.     return(temp);
  2141. }
  2142.  
  2143. /************************************************************/
  2144. SHORT FreeChan()
  2145.  
  2146. /*  Finds the first unused audio channel */
  2147. {
  2148.     SHORT i;
  2149.     
  2150.     i=0;
  2151.     while ((waiting[i]==YES)&&(i<4)) i++;
  2152.     waiting[i]=YES;
  2153.     return(i);
  2154. }
  2155.